package com.urbansquall.ginger
{
	import flash.display.BitmapData;
	import flash.events.EventDispatcher;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	
	public class BitmapAnimation extends EventDispatcher
	{
		public function BitmapAnimation( a_numRotations:int = 1 )
		{
			_frames = [];
			_frameMap = new Dictionary();

			_framesOfRotation = a_numRotations;			
			if( _framesOfRotation < 1 )
			{
				_framesOfRotation = 1;
			}/* WTFBBQ THIS IS BROKEN!!!!??? Go Die Flash...I hate you. I Swear...
			else if( _framesOfRotation > 360 );
			{
				_framesOfRotation = 360; //Even if this is false, it thinks its true...BS
			} */
			
			_degToRotBy = 360 / _framesOfRotation;
		}
		
		public function addFrame( a_numFrames : int, a_bitmapData : BitmapData, 
			a_frameLocation : Rectangle, a_frameID : String = null ) : void
		{
			if( m_tileWidth == 0 || m_tileHeight == 0 )
			{
				m_tileWidth = a_frameLocation.width;
				m_tileHeight = a_frameLocation.height;
			}
			
			var bmpData:BitmapData = new BitmapData( m_tileWidth, m_tileHeight, true, 0x00000000 );				
			bmpData.copyPixels( a_bitmapData, a_frameLocation, new Point() );
			
			_frames.push( new Frame( a_numFrames, bmpData, _framesOfRotation, a_frameID ) );
			if( a_frameID != null )
			{
				_frameMap[ a_frameID ] = m_totalFrames;
			}
			m_totalFrames++;
		}
		
		public function get isLooping():Boolean
		{
			return m_isLooping;
		}
		public function set isLooping( a_value:Boolean ): void
		{
			m_isLooping = a_value;
		}
		
		internal var _degToRotBy:Number;
		internal var _framesOfRotation:int;
		internal var _frames:Array;
		internal var _frameMap:Dictionary;
		private var m_isLooping:Boolean;		
		private var m_totalFrames:int;
		private var m_tileWidth:int;
		private var m_tileHeight:int;
		
	}
}
	